﻿namespace Triad.Controls
{
    #region Usings

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using AttributeCollection = System.ComponentModel.AttributeCollection;

    #endregion

    /// <summary>
    /// 
    /// </summary>
    //[PropertyTab(typeof(Triad.ControlsTab), PropertyTabScope.Document)]
    public partial class tfListView : ICustomTypeDescriptor
    {
        private static readonly string c_NewLine = Environment.NewLine;
        private bool c_ClearAllSelectedRows = false;
        
        private string c_ResourcePath = String.Empty;
       
        private readonly string[] c_EventsToRemove = {
                                                       "SelectedIndexChanged",
                                                       "SelectedIndexChanging",
                                                       "PageIndexChanged",
                                                       "PageIndexChanging",
                                                       "RowCancelingEdit",
                                                       "RowCommand",
                                                       "RowDeleted",
                                                       "RowDeleting",
                                                       "RowUpdated",
                                                       "RowUpdating",
                                                       "RowEditing",
                                                       "Sorted",
                                                       "Sorting",
                                                       "TextChanged",
                                                       "DataBinding",
                                                       "DataBound",
                                                       "RowDataBound"
                                                   };

        private readonly string[] c_PropsToRemove = {
                                                      "AccesibilityObject",
                                                      "BackColor",
                                                      "BackImageUrl",
                                                      "BorderColor",
                                                      "BorderStyle",
                                                      "BorderWidth",
                                                      "CssClass",
                                                      "Font",
                                                      "Caption",
                                                      "AccessibleDescription",
                                                      "AccessibleName",
                                                      "AllowDrop",
                                                      "BackgroundImage",
                                                      "Capture",
                                                      "DisplayRectangle",
                                                      "Enabled",
                                                      "EnableSortingAndPagingCallbacks",
                                                      "EnableTheming",
                                                      "EnableViewState",
                                                      "SkinID",
                                                      "CellPadding",
                                                      "CellSpacing",
                                                      "HorizontalAlign",
                                                      "ForeColor",
                                                      "Region",
                                                      "Tag",
                                                      "Text",
                                                      "Visible",
                                                      "Width",
                                                      "Height",
                                                      "AutoGenerateDeleteButton",
                                                      "AutoGenerateAddButton",
                                                      "AutoGenerateUpdateButton",
                                                      "AlternatingRowStyle",
                                                      "EditRowStyle",
                                                      "EmptyDataRowStyle",
                                                      "FooterStyle",
                                                      "HeaderStyle",
                                                      "PagerStyle",
                                                      "RowStyle",
                                                      "SelectedRowStyle",
                                                      "PagerSettings",
                                                      "UseAccessibleHeader",
                                                      "RowHeaderColumn",
                                                      "CaptionAlign"
                                                  };
        #region Exposed Attributes

        private string _templateTitle = string.Empty;
        [Category("ListView Features"),
         PropertyTab("Triad.ControlsTab"),
         DefaultValue(""),
         Description("Sets the Template Title")
        ]
        public string TemplateTitle
        {
            get
            {
                return _templateTitle;
            }
            set { _templateTitle = value; }
        }

        private bool IsDesignTime
        {
            get { return Site != null && Site.DesignMode; }
        }

        private object _tfDataSource;

        /// <summary>
        /// Holds the datasource information
        /// </summary>
        /// <value>The tf data source.</value>
        [
            Category("Data"),
            PropertyTab("Triad.ControlsTab"),
            DefaultValue(false),
            Description("use this instead of DataSource"),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public object tfDataSource
        {
            get { return _tfDataSource; }
            set { _tfDataSource = value; }
        }

        private bool freezeHeader=true;
        /// <summary>
        /// Freeze Header : True/False
        /// 
        /// Default: False
        /// </summary>
        [Browsable(true),
         Category("Freeze"),
         PropertyTab("tfControl"),
         Description("Freeze Header."),
         DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
        public bool FreezeHeader
        {
            get { return freezeHeader; }
            set
            {
                freezeHeader = value;
                if (freezeHeader)
                {
                    UseAccessibleHeader = true;
                    //If user hasnt set height property set a default here.
                    if (GridHeight == Unit.Empty)
                        GridHeight = 400;
                }
            }
        }

        ///// <summary>
        ///// Specify here how many columns you want to freeze in the grid, 
        ///// freeze columns from the left.
        ///// 
        ///// Default: 0
        ///// </summary>
        //[Browsable(true),
        // Category("Freeze"),
        // PropertyTab("Triad.ControlsTab"),
        // DefaultValue("0"),
        // Description("Specify whether or not first column (selector) is frozen.")]
        //public bool FreezeColumnOne { get; set; }

        private Unit gridHeight = Unit.Pixel(400);

        /// <summary>
        /// Grid height, this is actually height of 'DIV' tag not of 'table' which can be set through "Height"
        /// </summary>
        [Browsable(true),
         Category("Freeze"),
         PropertyTab("Triad.ControlsTab"),
         Description("Grid height, this is actually height of <DIV> tag not of <table> which can be set through Height."),
         DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public Unit GridHeight
        {
            get { return gridHeight; }
            set { gridHeight = value; }
        }

        private Unit gridWidth =Unit.Percentage(100);

        /// <summary>
        /// Grid width, this is actually width of 'DIV' tag not of 'table' which can be set through "Width"
        /// </summary>
        [Browsable(true),
         Category("Freeze"),
         PropertyTab("Triad.ControlsTab"),
         Description("Grid width, this is actually width of <DIV> tag not of <table> which can be set through Width."),
         DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public Unit GridWidth
        {
            get
            {
                return gridWidth;
            }
            set { gridWidth = value; }
        }

        /// <summary>
        /// <para>The ToolTip you'ld like to show when hovering a column border.</para>
        /// </summary>
        [
            Category("Appearance"),
            PropertyTab("Triad.ControlsTab"),
            DefaultValue("Drag to adjust width."),
            Description("The ToolTip you'ld like to show when hovering a column border."),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public override string ToolTip
        {
            get
            {
                var s = (string)ViewState["ToolTip"];
                return s ?? "Drag to adjust width.";
            }
            set { ViewState["ToolTip"] = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the grid is in debug mode.
        /// </summary>
        /// <value><c>true</c> if in debug mode; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:18 PM
        /// Modified By: 
        /// </remarks>
        [
            Category("ListView Features"),
            PropertyTab("Triad.ControlsTab"),
            DefaultValue(false),
            Description("Whether or not the Grid is in Debug Mode"),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)
        ]
        public bool DebugMode { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is disabled.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is disabled; otherwise, <c>false</c>.
        /// </value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [
            DefaultValue(false),
            Browsable(false)
        ]
        public bool IsDisabled(DataRow row)
        {
            if(row["_tfAT"].ToString().EndsWith("1"))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is selected.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is selected; otherwise, <c>false</c>.
        /// </value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [
            DefaultValue(false),
            Browsable(false)
        ]
        public bool IsSelected(DataRow row)
        {
            if(row["_tfAT"].ToString().StartsWith("1"))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Gets the selected row count.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [DefaultValue(0),Browsable(false)]
        public int GetSelectedRowCount()
        {
            DataRow[] rowList = c_MyTable.Select("_tfAT = '10'");
            return rowList.Length;
        }

        /// <summary>
        /// Selects the row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="isSelected">if set to <c>true</c> [is selected].</param>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [DefaultValue(0), Browsable(false)]
        public void SelectRow(DataRow row, bool isSelected)
        {
            if (isSelected)
            {
                c_MyTable.Rows[c_MyTable.Rows.IndexOf(row)]["_tfAT"]="10";
            }
            else
            {
                c_MyTable.Rows[c_MyTable.Rows.IndexOf(row)]["_tfAT"] = "00";
            }
        }

        /// <summary>
        /// Selects the row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="isDisabled">if set to <c>true</c> [is selected].</param>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [DefaultValue(0), Browsable(false)]
        public void DisableRow(DataRow row, bool isDisabled)
        {
            if (isDisabled)
            {
                c_MyTable.Rows[c_MyTable.Rows.IndexOf(row)]["_tfAT"] = "01";
            }
            else
            {
                if (IsSelected(row))
                {
                    c_MyTable.Rows[c_MyTable.Rows.IndexOf(row)]["_tfAT"] = "10";
                }
                else
                {
                    c_MyTable.Rows[c_MyTable.Rows.IndexOf(row)]["_tfAT"] = "00";
                }
            }
        }

        /// <summary>
        /// Clears all selected rows.
        /// </summary>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [Browsable(false)]
        public void ClearAllSelectedRows() {
            foreach (DataRow e in c_MyTable.Rows)
            {
                e["_tfAT"] = "00";
            }
        }

        //[DefaultValue(-1),Browsable(false)]
        //public void ClearSelectedRowAt(int rowIndex) { _ClearIndex = rowIndex; }


        /// <summary>
        /// Gets or sets a value indicating whether [allow edit template].
        /// </summary>
        /// <value><c>true</c> if [allow edit template]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By: 
        /// </remarks>
        [
            Category("ListView Features"),
            DefaultValue(false),
            PropertyTab("Triad.ControlsTab"),
            Description("Allow Edit Templates to be used"),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
            DisplayName("Allow Edit Template")
        ]
        public bool AllowEditTemplate { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [allow multi select].
        /// </summary>
        /// <value><c>true</c> if [allow multi select]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [
            Category("ListView Features"),
            DefaultValue(false),
            PropertyTab("Triad.ControlsTab"),
            Description("Allow the use of Ctrl/Shift while selecting multiple rows"),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
            DisplayName("Allow MultiSelect")
        ]
        public bool AllowMultiSelect { get; set; }

        private bool allowUserSelection=true;

        /// <summary>
        /// Gets or sets a value indicating whether [allow user selection].
        /// </summary>
        /// <value><c>true</c> if [allow user selection]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [
            Category("ListView Features"),
            DefaultValue(true),
            PropertyTab("Triad.ControlsTab"),
            Description("Let the user select items, otherwise only server-side selection is allowed"),
            DisplayName("Allow User Selection")
        ]
        public bool AllowUserSelection
        {
            get { return allowUserSelection; }
            set { allowUserSelection = value; }
        }

        private bool sendAllRowsInCallback=false;
        /// <summary>
        /// Gets or sets a value indicating whether [allow user selection].
        /// </summary>
        /// <value><c>true</c> if [allow user selection]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [
            Category("ListView Features"),
            DefaultValue(false),
            PropertyTab("Triad.ControlsTab"),
            Description("Allow the callback on updateserver to include a datatable with ALL rows in the grid vs. just changes"),
            DisplayName("Send ALL Rows in Callback")
        ]
        public bool SendAllRowsInCallback
        {
            get { return sendAllRowsInCallback; }
            set { sendAllRowsInCallback = value; }
        }

        private bool readOnly=false;

        /// <summary>
        /// Gets or sets a value indicating whether [read only].
        /// </summary>
        /// <value><c>true</c> if [read only]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:20 PM
        /// Modified By: 
        /// </remarks>
        [
            Category("ListView Features"),
            PropertyTab("Triad.ControlsTab"),
            DefaultValue(false),
            Description("Make the grid Read-Only (Row selection only)")
        ]
        public bool ReadOnly
        {
            get { return readOnly; }
            set { readOnly = value; }
        }

        private bool allowEdit=false;

        /// <summary>
        /// Gets or sets a value indicating whether [allow edit].
        /// </summary>
        /// <value><c>true</c> if [allow edit]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), PropertyTab("Triad.ControlsTab"), DefaultValue(false), Description("Allow Editing"),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
         DisplayName("Allow Edit")]
        public bool AllowEdit
        {
            get { return allowEdit; }
            set { allowEdit = value; }
        }

        private bool allowDelete=false;

        /// <summary>
        /// Gets or sets a value indicating whether [allow delete].
        /// </summary>
        /// <value><c>true</c> if [allow delete]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), PropertyTab("Triad.ControlsTab"), DefaultValue(false),
         Description("Allow Deletion of Rows"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
         DisplayName("Allow Delete")]
        public bool AllowDelete
        {
            get { return allowDelete; }
            set { allowDelete = value; }
        }

        private bool allowAdd=false;

        /// <summary>
        /// Gets or sets a value indicating whether [allow add].
        /// </summary>
        /// <value><c>true</c> if [allow add]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), PropertyTab("Triad.ControlsTab"), DefaultValue(false),
         Description("Allow Adding of Rows"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
         DisplayName("Allow Add")]
        public bool AllowAdd
        {
            get { return allowAdd; }
            set { allowAdd = value; }
        }


        private bool allowSearch=false;

        /// <summary>
        /// Gets or sets a value indicating whether [allow search].
        /// </summary>
        /// <value><c>true</c> if [allow search]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), PropertyTab("Triad.ControlsTab"), DefaultValue(false),
         Description("Allow text search on cells (displayed on top of grid)"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
         DisplayName("Allow Search")]
        public bool AllowSearch
        {
            get { return allowSearch; }
            set { allowSearch = value; }
        }

        private bool allowMoveRows=false;

        /// <summary>
        /// Gets or sets a value indicating whether [allow move rows].
        /// </summary>
        /// <value><c>true</c> if [allow move rows]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), PropertyTab("Triad.ControlsTab"), DefaultValue(false),
         Description("Allows End user to move rows up and down"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
         DisplayName("Allow Move Rows")]
        public bool AllowMoveRows
        {
            get { return allowMoveRows; }
            set { allowMoveRows = value; }
        }


        private bool renderOnClient=true;

        /// <summary>
        /// Gets or sets a value indicating whether [render on client].
        /// </summary>
        /// <value><c>true</c> if [render on client]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), PropertyTab("Triad.ControlsTab"), DefaultValue(true),
         Description("Information is rendered at Server and sent as HTML vs Rendered at Client via Javascript"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
         DisplayName("Render On Client")]
        public bool RenderOnClient
        {
            get { return renderOnClient; }
            set { renderOnClient = value; }
        }

        private bool allowGroupBy=false;

        /// <summary>
        /// Gets or sets a value indicating whether [allow group by].
        /// </summary>
        /// <value><c>true</c> if [allow group by]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By:
        /// </remarks>
        [Category("ListView Features"), DefaultValue(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
         Description("Allow for column headings to be dragged/dropped on the Grouping header"),
         PropertyTab("Triad.ControlsTab")]
        public bool AllowGroupBy
        {
            get { return allowGroupBy; }
            set { allowGroupBy = value; }
        }

        private bool allowResize;

        /// <summary>
        /// Gets or sets a value indicating whether [allow resize].
        /// </summary>
        /// <value><c>true</c> if [allow resize]; otherwise, <c>false</c>.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), DefaultValue(false), Description("Allow for Column Resizing"),
         PropertyTab("Triad.ControlsTab"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), 
         DisplayName("Allow Resize")]
        public bool AllowResize
        {
            get { return allowResize; }
            set { allowResize = value; }
        }

        private string hiddenColumns;

        /// <summary>
        /// Gets or sets the hidden columns.
        /// </summary>
        /// <value>The hidden columns.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), DefaultValue("*"), Description("Comma Delimited column names to hide during rendering"), DisplayName("Hidden Columns"),
         PropertyTab("Triad.ControlsTab")]
        public string HiddenColumns
        {
            get { return hiddenColumns; }
            set { hiddenColumns = value; }
        }

        private string readOnlyColumns;

        /// <summary>
        /// Gets or sets the hidden columns.
        /// </summary>
        /// <value>The hidden columns.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:10 AM
        /// Modified By: 
        /// </remarks>
        [Category("ListView Features"), DefaultValue("*"), Description("Comma Delimited column names that are Read Only in edit mode"), DisplayName("ReadOnly Columns"),
         PropertyTab("Triad.ControlsTab")]
        public string ReadOnlyColumns
        {
            get { return readOnlyColumns; }
            set { readOnlyColumns = value; }
        }

        //       public override object DataSource
 //       {
 //           get
 //           {
 //               if (!IsDesignTime)
 //               {
 //                   if(HttpContext.Current.Cache[ClientID + "DS"]==null)
 //                   {
                        
 //                   }
 ////If DataGridCache is Nothing Then
 ////   'Populate the DataSet with data from the database
 ////   Const CommandText As String = _
 ////          "SELECT FAQID, Description FROM tblFAQ ORDER BY FAQID"

 ////   'The connection to our database
 ////   Dim myConnection as New _
 ////       SqlConnection(ConfigurationSettings.AppSettings("connectionString"))

 ////   Dim myCommand As New SqlDataAdapter(CommandText, myConnection)
 ////   Dim DS As New DataSet()

 ////   myCommand.Fill(DS)
    
 ////   'Specify the DataSource for the DataGrid is the DataSet 
 ////   'we just populated
 ////   MyDataGrid.DataSource = DS

 ////   'Now insert dataset into cache, specifying that it should 
 ////   'expire in 10 minutes
 ////   Cache.Insert ("DataGridCache", DS, Nothing, _
 ////           DateTime.Now.AddMinutes(10), TimeSpan.Zero)


 //                   return HttpContext.Current.Cache[ClientID + "DS"]; 
 //               }
 //                   return base.DataSource;    
 //           }
 //           set
 //           {
 //               if (!IsDesignTime)
 //               {
 //                   if (value == null)
 //                       HttpContext.Current.Cache.Remove(ClientID + "DS");
 //                   else
 //                   {
 //                       HttpContext.Current.Cache[ClientID + "DS"] = value;
 //                   }
 //               }

 //               base.DataSource = value;

 //           }
 //       }


        /// <summary>
        /// Gets or sets the resource path.
        /// </summary>
        /// <value>The resource path.</value>
        /// <remarks>
        /// Author: tim.fischer,   5/19/2008 - 2:19 PM
        /// Modified By: 
        /// </remarks>
        [
            PropertyTab("Triad.ControlsTab"),
            Category("ListView Features"),
            DefaultValue("~/Triad.Controls/"),
            Description("Base URL for css and images"),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)
        ]
        public string ResourcePath
        {
            get
            {
                if (c_ResourcePath == String.Empty)
                {
                    return ResolveClientUrl("~/Triad.Controls/");
                }
                if (c_ResourcePath.EndsWith("/") || c_ResourcePath.EndsWith("\\"))
                {
                    return ResolveClientUrl(c_ResourcePath);
                }
                return c_ResourcePath + "/";
            }
            set { c_ResourcePath = value; }
        }

        private string CSSPath
        {
            get { return c_ResourcePath + "css/"; }
        }

        private string JSPath
        {
            get { return c_ResourcePath + "js/"; }
        }

        private string IMGPath
        {
            get { return c_ResourcePath + "images/"; }
        }

        #endregion

        #region STYLES
        //[TypeConverter(typeof(ExpandableObjectConverter))]
        //public EmployeeCollection Employees
        //{
        //    get { return employees; }
        //}
        //private static lvTheme _cssTheme = new lvTheme();
        /// <summary>
        /// Gets or sets the type of the combo box.
        /// </summary>
        /// <value>The type of the combo box.</value>
        [Category("tfListView"),
         DefaultValue("red"),
        DisplayName("CSS Theme"),
        TypeConverter(typeof(lvThemeConverter))]
        public String CSSTheme
        {
            get
            {
                Object cbType = ViewState[ID + "Theme"];
                if (cbType != null)
                {
                    return (String)cbType;
                }
                return "red";
            }
            set
            {
                ViewState[ID + "Theme"] = value;
            }

        }

        /// <summary>
        /// Gets or sets the CSSTHEMES.
        /// </summary>
        /// <value>The CSSTHEMES.</value>
        /// <remarks>
        /// Author: tim.fischer,   8/26/2008 - 9:11 AM
        /// Modified By: 
        /// </remarks>
        //[
        // PersistenceMode(PersistenceMode.InnerProperty),
        // Browsable(true),
        // Category("CSS-Styles"),
        // DescriptionAttribute("Test")
        //]
        //public string CSSTHEMES { get; set; }
        //[Browsable(true),
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //Category("Style")
        //]
        //public Style HeaderClass
        //{
        //    get
        //    {
        //        if (headerClass == null)
        //        {
        //            headerClass = new Style();

        //        }
        //        return headerClass;
        //    }
        //    set
        //    {
        //        headerClass = value;
        //    }
        //}

        //[
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //Category("Style")
        //]
        //public string PagerClass
        //{
        //    get;
        //    set;
        //}

        //[
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //Category("Style")
        //]
        //public string SelectedRowClass
        //{
        //    get;
        //    set;
        //}

        //[
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //Category("Style")
        //]
        //public string RowClass
        //{
        //    get;
        //    set;
        //}
        //[
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //Category("Style")
        //]
        //public string AlternatingRowClass
        //{
        //    get;
        //    set;
        //}

        //[
        //    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //    NotifyParentProperty(true),
        //    PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //    Category("Style")
        //]
        //public string SearchClass
        //{
        //    get;set;
        //}

        //[
        //    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //    NotifyParentProperty(true),
        //    PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //    Category("Style")
        //]
        //public string GroupByTableClass
        //{
        //    get;set;
        //}

        //[
        //    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //    NotifyParentProperty(true),
        //    PersistenceMode(PersistenceMode.InnerProperty),
        //    CssClassPropertyAttribute,
        //    Category("Style")
        //]
        //public string GroupByTableItemClass
        //{
        //    get;set;
        //}

        //[
        //    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //    NotifyParentProperty(true),
        //    PersistenceMode(PersistenceMode.InnerProperty),
        //    CssClassPropertyAttribute,
        //    Category("Style")
        //]
        //public string GroupByItemClass
        //{
        //    get; set;
        //}

        //[
        //    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //    NotifyParentProperty(true),
        //    PersistenceMode(PersistenceMode.InnerProperty),
        //    CssClassPropertyAttribute,
        //    Category("Style")
        //]

        //public string SelectorItemSingleClass
        //{
        //    get; set;
        //}


        //[
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //Category("Style")
        //]
        //public string SelectorItemMultiClass
        //{
        //    get; set;
        //}
        //[
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //Category("Style")
        //]
        //public string EditRowClass
        //{
        //    get;
        //    set;
        //}

        //[
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        //NotifyParentProperty(true),
        //PersistenceMode(PersistenceMode.InnerProperty),
        //CssClassPropertyAttribute,
        //Category("Style")
        //]
        //public string FooterClass
        //{
        //    get;
        //    set;
        //}

        #endregion


        /// <summary>
        /// Gets or sets the debug HTML (HTML used to build the grid).
        /// </summary>
        /// <value>The HTML used to build the Grid.</value>
        public string GetDebugHTML { get; set; }

        //Does the property filtering...
        private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection pdc)
        {
            var toRemove = new ArrayList();
            foreach (string s in c_PropsToRemove)
                toRemove.Add(s);

            var adjustedProps = new PropertyDescriptorCollection(new PropertyDescriptor[] { });
            foreach (PropertyDescriptor pd in pdc)
                if (!toRemove.Contains(pd.Name))
                    adjustedProps.Add(pd);

            return adjustedProps;
        }

        //private EventDescriptorCollection FilterEvents(EventDescriptorCollection pdc)
        //{
        //    var toRemove = new ArrayList();
        //    foreach (string s in c_EventsToRemove)
        //        toRemove.Add(s);

        //    var adjustedProps = new EventDescriptorCollection(new EventDescriptor[] { });
        //    foreach (EventDescriptor pd in pdc)
        //    {
        //        if (!toRemove.Contains(pd.Name))
        //            adjustedProps.Add(pd);
        //    }

        //    return adjustedProps;
        //}


        #region ICustomTypeDescriptor Members

        EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
        {
            return TypeDescriptor.GetEvents(this, true);
        }

       PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
        {
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this, true);
            return FilterProperties(pdc);
        }

        AttributeCollection ICustomTypeDescriptor.GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, true);
        }

        string ICustomTypeDescriptor.GetClassName()
        {
            return TypeDescriptor.GetClassName(this, true);
        }

        string ICustomTypeDescriptor.GetComponentName()
        {
            return TypeDescriptor.GetComponentName(this, true);
        }

        TypeConverter ICustomTypeDescriptor.GetConverter()
        {
            return TypeDescriptor.GetConverter(this, true);
        }

        EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(this, true);
        }

        PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(this, true);
        }

        object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(this, editorBaseType, true);
        }

        EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(this, attributes, true);
        }

        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this, attributes, true);
            return FilterProperties(pdc);
        }

        object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }

        #endregion
    }
}
